﻿using SUNRPA.CONTROLS.IMPL.util;
using System;
using System.Globalization;
using System.IO;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace RPAVIEW.views.EditPage.flows {
    public class BaseParamViewAction : UserControl {
        public BaseParamViewAction() {
            this.Resources.Add("validationOutData", new ValidationTempData());
        }
        public virtual void UpdateSource() { 
        }
    }

    public class ImagePathConverter : IValueConverter {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            string path = (string)value;
            if(string.IsNullOrEmpty(path) || !File.Exists(path)) { 
                return new BitmapImage();
            }
            return new BitmapImage(new Uri(Path.GetFullPath(path)));
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            BitmapImage image = value as BitmapImage;
            if(image == null) {
                return "";
            }
            return image.UriSource.AbsolutePath;
        }
    }
}
